package com.example.smart.dialog

import android.app.Activity
import android.view.Gravity
import android.view.View
import com.example.lib.extend.cleanText
import com.example.lib.extend.getDeviceWidth
import com.example.lib.extend.setOnDoubleClickListener
import com.example.lib.extend.stringText
import com.example.lib.utils.AppUtils
import com.example.lib.utils.ToastUtils
import com.example.smart.R
import com.example.smart.base.dialog.base.BaseDialog
import com.example.smart.databinding.DialogInputBinding
import com.example.smart.utils.handler.HandUtils

class InputDialog(val activity: Activity) : BaseDialog<DialogInputBinding>(dialogContext = activity,
    width = (getDeviceWidth(activity)),
    gravity = Gravity.BOTTOM,
    style = R.style.inputDialogStyle) {

    var onSend: ((String) -> Unit)? = null

    override fun setLayoutRes() = R.layout.dialog_input

    override fun afterViewCreate(view: View?) {
        binding.Send.setOnDoubleClickListener {
            val text = binding.Edit.stringText()
            if (text.isEmpty()) {
                ToastUtils.showToast("请输入问题")
                return@setOnDoubleClickListener
            }
            binding.Edit.cleanText()
            onSend?.invoke(text)
            dismiss()
        }
    }

    override fun show() {
        super.show()
        HandUtils.postTask({
            AppUtils.showInputKey(activity, binding.Edit)
        }, 200)
    }
}